package com.leha.core.services.imp;

import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.WxMaInMemoryConfig;
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder;
import org.apache.http.HttpResponse;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.conn.ConnectionKeepAliveStrategy;
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.protocol.HttpContext;

import java.util.concurrent.TimeUnit;

//@Service
public class WeixinService extends WxMaServiceImpl {
    WeixinService(String appid, String secret, String token, String aeskey, String format) {
        final WxMaInMemoryConfig config = new WxMaInMemoryConfig();
        config.setAppid(appid);
        config.setSecret(secret);
        config.setToken(token);
        config.setAesKey(aeskey);
        config.setMsgDataFormat(format);

        DefaultApacheHttpClientBuilder clientBuilder = DefaultApacheHttpClientBuilder.get();
        clientBuilder.setIdleConnTimeout(20*1000);//空闲链接的超时时间(单位ms)
        clientBuilder.setCheckWaitTime(19*1000);//空闲链接的检测周期(单位ms)
        config.setApacheHttpClientBuilder(clientBuilder);
        super.setWxMaConfig(config);
    }
}
